package com.vs.wms.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.vs.wms.common.CommonDao;
import com.vs.wms.dao.AdminDao;
import com.vs.wms.pojo.Admin;

public class AdminDaoImpl extends CommonDao implements AdminDao {

	/* (non-Javadoc)
	 * @see com.vs.wms.dao.AdminDao#getAdmins()
	 */
	@SuppressWarnings("unchecked")
	public List<Admin> getAdmins() {
		
		List<Admin> lstAdmin = new ArrayList<Admin>();
		
		try {
			
			lstAdmin = sqlMap.queryForList("AdminInfo.getAdmins", null);
		} 
		catch (SQLException e) {
			
			e.printStackTrace();
		}
		
		return lstAdmin;
	}
	
	/* (non-Javadoc)
	 * @see com.vs.wms.dao.AdminDao#getAdminByUP(java.lang.String, java.lang.String)
	 */
	public Admin getAdminByUP(String userName, String userPass) {
		
		Object object = null;
		Admin admin = null;
		Map<String, String> adminInfo = new HashMap<String, String>();
		
		adminInfo.put(Admin.PROP_USER_NAME, userName);
		adminInfo.put(Admin.PROP_USER_PASS, userPass);
		
		try {
			
			object = sqlMap.queryForObject("AdminInfo.getAdminsByUP", adminInfo);
		} 
		catch (SQLException e) {
			
			e.printStackTrace();
		}
		
		if (object != null) {
			
			admin = (Admin) object;
		}
		
		return admin;
	}

	/* (non-Javadoc)
	 * @see com.vs.wms.dao.AdminDao#getAdminById(int)
	 */
	@Override
	public Admin getAdminById(int id) {
		
		Object object = null;
		Admin admin = null;
		Map<String, Integer> adminInfo = new HashMap<String, Integer>();
		
		adminInfo.put(Admin.PROP_ID, id);
		
		try {
			
			object = sqlMap.queryForObject("AdminInfo.getAdminsById", adminInfo);
		} 
		catch (SQLException e) {
			
			e.printStackTrace();
		}
		
		if (object != null) {
			
			admin = (Admin) object;
		}
		
		return admin;
	}
}